package com.yiwyn;

import com.yiwyn.domain.Animal;
import com.yiwyn.domain.Cat;
import com.yiwyn.domain.Dog;

import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;

public class Main {

    public static void main(String[] args) {

//        List<Cat> list = new ArrayList<>(Collections.singletonList(new Cat()));
//        mList(list);
//
//        List<Animal> list1 = new ArrayList<>(Collections.singletonList(new Dog()));
//        mList1(list1);


        List<Animal> list1 = new ArrayList<>(Collections.singletonList(new Dog()));
        mList1(list1);


        List<Animal> elements = new ArrayList<>();
        // 这里从elements中获取到了Animal,可以理解为elements作为生产者提供了一个Animal元素
        Animal animal = elements.get(0);
        // 这里elements添加了一个元素，可以理解为elements消费了一个元素
        elements.add(new Animal());

    }

    // P E C S
    // product extends  & consumer super

    public static <T extends Animal> void call(T a) {
        a.call();
    }

    public static void call1(Class<? super Animal> clazz) {
        System.out.println(clazz);
    }

    public static void mList(List<? extends Animal> list) {
        for (Animal animal : list) {
            animal.call();
        }
    }

    public static void mList1(List<? super Animal> list) {
        list.add(new Cat());
        for (Object o : list) {
            System.out.println(o);
        }
    }

}